import * as type from './type'
import http from 'Utils/http'

const actions = {
    // 获得购物车
    async getShopCar({ commit }, value) {

        let products = ''
        value.some(item => {
            products += `${item.code}%7C%7C${item.num},`
        })
        products = products.substring(0, products.lastIndexOf(','))


        const result = await http('https://wcgi.jianke.com/v3/memberShopCarts/offline/promo', {
            products: products,
            sourceHost: 'm.jianke.com',
        }, true)

        let action = {
            type: type['GETCAR'],
            payload: result
        }
        commit(action)
    },
    // 添加购物车
    joinShopCar({ commit }, value) {
        let action = {
            type: type['JOINCAR'],
            payload: value
        }

        commit(action)
    }

}

export default actions